package com.adcc.ags.utility.mq.transfer.manager;

import com.adcc.ags.utility.mq.configuration.MQConfiguration;
import com.adcc.ags.utility.mq.entity.Channel;
import com.adcc.ags.utility.mq.entity.Queue;
import com.adcc.ags.utility.mq.entity.Topic;
import com.adcc.ags.utility.mq.transfer.MQConnectionPool;
import com.adcc.ags.utility.mq.transfer.MQTransferImpl;
import com.google.common.base.Optional;
import com.ibm.mq.MQQueueManager;

import java.util.List;

/**
 * MQManager
 */
public abstract class MQManager {

    // MQConfiguration
    protected MQConfiguration configuration;

    // MQConnectionPool
    protected MQConnectionPool connectionPool;

    /**
     * 构造函数
     */
    public MQManager(){

    }

    /**
     * 构造函数
     * @param configuration
     */
    public MQManager(MQConfiguration configuration){
        this.configuration = configuration;
    }

    /**
     * 构造函数
     * @param configuration
     * @param connectionPool
     */
    public MQManager(MQConfiguration configuration,MQConnectionPool connectionPool){
        this.configuration = configuration;
        this.connectionPool = connectionPool;
        this.connectionPool.initConnectionManager();
    }

    public void  setConfiguration(MQConfiguration configuration){
        this.configuration = configuration;
    }

    public void setConnectionPool(MQConnectionPool connectionPool){
        this.connectionPool = connectionPool;
        this.connectionPool.initConnectionManager();
    }

    /**
     * 取得QueueManager
     * @return
     */
    public abstract MQQueueManager getQueueManager() throws Exception;

    /**
     * 返还QueueManager
     * @param mqm
     * @throws Exception
     */
    public abstract void returnQueueManager(MQQueueManager mqm) throws Exception;

    /**
     * 创建通道
     * @param channel
     */
    public abstract void createChannel(Optional<Channel> channel) throws Exception;

    /**
     * 删除通道
     * @param channel
     */
    public abstract void deleteChannel(String channel) throws Exception;

    /**
     * 更新通道
     * @param channel
     * @throws Exception
     */
    public abstract void updateChannel(Optional<Channel> channel) throws Exception;

    /**
     * 查询通道
     * @return
     * @throws Exception
     */
    public abstract List<Channel> findChannel(String name,int type) throws Exception;

    /**
     * 查询通道
     * @return
     * @throws Exception
     */
    public abstract List<Channel> findChannel(String name) throws Exception;

    /**
     * 创建队列
     * @param queue
     * @throws Exception
     */
    public abstract void createQueue(Optional<Queue> queue) throws Exception;

    /**
     * 删除队列
     * @param queue
     */
    public abstract void deleteQueue(String queue) throws Exception;

    /**
     * 更新队列
     * @param queue
     * @throws Exception
     */
    public abstract void updateQueue(Optional<Queue> queue) throws Exception;

    /**
     * 查询所有队列
     * @return
     * @throws Exception
     */
    public abstract List<Queue> findQueue(String name,int type) throws Exception;


    /**
     * 创建主题
     * @param topic
     * @throws Exception
     */
    public abstract void createTopic(Optional<Topic> topic) throws Exception;

    /**
     * 删除主题
     * @param topic
     * @throws Exception
     */
    public abstract void deleteTopic(String topic) throws Exception;

    /**
     * 更新主题
     * @param topic
     * @throws Exception
     */
    public abstract void updateTopic(Optional<Topic> topic) throws Exception;

    /**
     * 查询主题
     * @param name
     * @param type
     * @return
     * @throws Exception
     */
    public abstract List<Topic> findTopic(String name,int type) throws Exception;
}
